package com.inda.lemurshooter;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class MenuActivity extends Activity implements OnClickListener{
	private  SoundPool aSoundPool;
	private int soundID1;
	private SharedPreferences settings;
	private final String SETTINGS_DATABASE="settings";
	private Editor editor;
	private boolean firstTime;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu_layout);
        
        
        // LJUD
    	aSoundPool = new SoundPool(6, AudioManager.STREAM_MUSIC, 0);
    	
    	// Show settings if it is the first time the user runs this game
    	settings= getSharedPreferences(SETTINGS_DATABASE, Context.MODE_PRIVATE);
    	firstTime = settings.getBoolean("firstTime", true);
    	if(firstTime)
    	{
    		showRules();
    		editor = settings.edit();
    		editor.putBoolean("firstTime", false);
    		editor.commit();
    	}
    	
    	
        
        //Register the buttons so that they become clickable
        View button1 = findViewById(R.id.BUTTON_PLAY);
        button1.setOnClickListener(this);
        View button2 = findViewById(R.id.BUTTON_RULES);
        button2.setOnClickListener(this);
        View button3 = findViewById(R.id.BUTTON_SETTINGS);
        button3.setOnClickListener(this);
        
        
    }

    /**
     * Each time a button is clicked this method is called with the button id.
     * @param The View object that is clicked
     */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
        case R.id.BUTTON_PLAY:
            startGame();
            break;
        case R.id.BUTTON_RULES:
            showRules();
            break;
        case R.id.BUTTON_SETTINGS:
            showSettings();
            break;
        }
	}
	
	private void showSettings() {
		Intent i = new Intent(this, SettingsActivity.class);
		startActivity(i);
	}

	private void showRules() {
		Intent i = new Intent(this, RulesActivity.class);
		startActivity(i);
	}

	// Starts the game activity
	private void startGame()
	{
		Intent i = new Intent(this, GameActivity.class);
		startActivity(i);
	}
}